<?php
declare(strict_types=1);

namespace App\Common\Query;

use Hyperf\Database\Model\Builder;

trait SearchTime
{
    /**
     * 时间搜索器
     * @param Builder $query
     * @param $time
     * @return void
     */
    public function searchTime(Builder $query, $time): void
    {
        if (is_array($time)) {
            if (isset($time[0]) && $time[0]) {
                $query->whereRaw("(`time`>=?)", [$time[0]]);
            }
            if (isset($time[1]) && $time[1]) {
                $query->whereRaw("(`time`<=?)", [$time[1]]);
            }
        }
    }
}